<template>
  <div class="page">
    <!-- <div class="p20">
      <div class="m1">
        <span class="">刷币资金总额:123233</span>
        <span class="ml20">已核销:123233</span>
        <span class="ml20">未核销:123233</span>
        <span class="ml20">单位:元</span>
      </div>
      <el-divider></el-divider>
    </div> -->
    <div class="s-search p20">
      <el-form
        :model="alone.searchForm.data"
        status-icon
        ref="ruleForm"
        :inline="true"
        class="demo-ruleForm"
      >
        <el-form-item>
          <el-date-picker
            v-model="alone.searchForm.data.dateTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="请选择开始时间"
            end-placeholder="请选择结束时间"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="alone.searchForm.data.rechargeType"
            placeholder="请选择充值方式"
          >
            <el-option label="线上" value="线上"> </el-option>
            <el-option label="线下" value="线下"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="alone.searchForm.data.checkStatus"
            placeholder="请选择状态"
          >
            <el-option
              v-for="item in alone.status"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="请输入平台账号"
            v-model="alone.searchForm.data.platformAccount"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="请输入主播昵称"
            v-model="alone.searchForm.data.pointAnchorNick"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            placeholder="请输入核销单号"
            v-model="alone.searchForm.data.checkNo"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            class="fr vam"
            icon="el-icon-search"
            @click="rSubmitSearchForm"
            type="primary"
            >搜索</el-button
          ></el-form-item
        >
      </el-form>
    </div>

    <div class="c-main p20">
      <div class="clearfix">
        <div class="fl">
          总共：{{ (pageAjax.paging && pageAjax.paging.total) || 0 }} 条
        </div>
      </div>
      <!-- 相关 -->
      <div class="c-aside clearfix"></div>
      <div class="c-section">
        <div class="c-body">
          <el-table
            border
            :data="pageAjax.data"
            stripe
            style="width: 100%"
            ref="table"
            @selection-change="rChangeTableItem"
          >
            <el-table-column label="序号" type="index"> </el-table-column>
            <el-table-column label="日期">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.beginTime + "-" + scope.row.endTime }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="充值方式">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.rechargeType }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="平台">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.platform }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="平台账号">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.platformAccount }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="币别">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.coinType }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="期初金额">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.originalMoney }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="充值金额">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.rechargeMoney }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="实际到账额">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.actualArrival }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="刷币总额">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.totalBrushCoin }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="本期金额">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.balanceMoney }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="针对性扶持主播昵称">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.pointAnchorNick }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="状态">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.checkStatus == 1 ? "已核销" : "未核销" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="核销单号">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.checkNo || "无" }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="创建时间">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.createTime }}
                </div>
              </template>
            </el-table-column>
            <el-table-column label="刷币损失(元)">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.brushPublicLose }}
                </div>
              </template>
            </el-table-column>

            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:agent_financePersonalrewardDetail
                  @click="showDrawer('detail', scope.row.id)"
                  >详情</el-button
                >
                <el-button
                  type="text"
                  size="small"
                  v-hasAuth:agent_financePersonalrewardDelete
                  @click="showDrawer('detail', scope.row.id)"
                  >删除</el-button
                >
                <span
                  v-hasAuth:agent_financePersonalrewardDetail-agent_financePersonalrewardDelete.invert
                  >—</span
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="c-footer">
          <div class="c-pagination">
            <el-pagination
              layout="prev, pager, next"
              @current-change="rPagingChange"
              @prev-click="rPagingChange"
              @next-click="rPagingChange"
              :current-page="pageAjax.paging.current"
              :total="pageAjax.paging.total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <el-drawer
      size="85%"
      :visible.sync="drawerCp.config.visible"
      :with-header="false"
    >
      <Details
        v-if="drawerCp.data.type == 'detail'"
        :biPlatformList="biPlatformListSupAjax.data"
        ref="detailCp"
        :id="drawerCp.data.id"
      />
    </el-drawer>
  </div>
</template>
<script>
// import excelMap from "./map.js";
import Details from "./components/details.vue";
import { getOffspringnTree } from "@/assets/js/util.js";
import { getBiPlatformList } from "@/api/others.js";
import { getRewardDetailIndex, getFinalCost } from "@/api/finance.js";

import _ from "lodash";

export default {
  name: "agent_cost",
  components: { Details },
  data: () => ({
    pageAjax: {
      btnDisabled: false,
      btnLoading: false,
      loading: false,
      lock: false,
      paging: {
        pages: 1, // 总页数
        current: 0, // 当前页
        total: 1, // 总数量
        pageSize: 10 // 每页数量
      },
      data: []
    },
    biPlatformListSupAjax: {
      data: []
    },
    orgSupAjax: {
      data: []
    },
    alone: {
      status: [
        {
          name: "全部",
          value: ""
        },
        {
          name: "已核销",
          value: "1"
        },
        {
          name: "未核销",
          value: "2"
        }
      ],
      searchForm: {
        loading: false,
        data: {
          searchStr: "",
          tenantType: "3",
          relType: 2
        }
      },
      tableSelected: []
    },
    translate: {},
    drawerCp: {
      config: {
        visible: false
      },
      data: {
        type: "add"
      }
    },
    orgCascaderCp: {
      config: {
        props: {
          value: "id",
          label: "name",
          multiple: false,
          emitPath: false,
          checkStrictly: true
        }
      }
    }
  }),
  created() {
    let _that = this;
    // _that.getPageData();
    _that.getOrgData();

    _that.getBiPlatformListData().then(() => {
      _that.getPageData();
    });
  },
  methods: {
    cancel() {
      let _that = this;
      _that.pageAjax.paging.current =
        _that.pageAjax.paging.current > 0
          ? _that.pageAjax.paging.current - 1
          : 0;
      _that.drawerCp.config.visible = false;

      _that.getPageData();
    },

    showDrawer(type, id) {
      let _that = this;
      _that.drawerCp.data.type = type;

      _that.drawerCp.config.visible = true;
      if (id) {
        _that.drawerCp.data.id = id;
        _that.$nextTick(() => {
          if (type == "detail") {
            _that.$refs.detailCp.getPageData();
          }
        });
      }
    },
    rChangeTableItem(val) {
      this.tableSelected = val;
    },
    rSubmitSearchForm() {
      let _that = this;
      if (_that.pageAjax.loading) {
        return;
      }
      _that.pageAjax.lock = false;
      _that.pageAjax.paging.current = 0;
      // if (!searchForm.data.searchStr && !searchForm.data.signWish && !searchForm.data.platform) {
      //   _that.$message.error({message: "搜索条件不能都为空", onClose: () => {
      //     _that.alone.searchForm.loading = false;
      //   }});
      //   return;
      // }
      _that.pageAjax.lock = false;
      _that.pageAjax.paging.current = 0;
      _that.getPageData();
    },
    rPagingChange(e) {
      let _that = this;
      _that.pageAjax.paging.current = e - 1;
      _that.getPageData();
    },
    getBiPlatformListData() {
      let _that = this;
      return getBiPlatformList()
        .then(resp => {
          let respData = resp.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            let translate = {};
            let arr = respData.data.filter(item => {
              if (item.value != "all") {
                translate[item.value] = item.name;
                return item;
              }
            });
            _that.biPlatformListSupAjax.data = arr;
            _that.translate.biPlatformList = translate;
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {});
    },
    getPageData() {
      let _that = this;
      let searchForm = _.cloneDeep(_that.alone.searchForm);
      let pageAjax = _that.pageAjax;

      if (pageAjax.loading || pageAjax.lock) {
        return;
      }

      let data = { ...searchForm.data };
      data.pageNo = _that.pageAjax.paging.current + 1;
      _that.pageAjax.loading = true;
      getRewardDetailIndex(data)
        .then(resp => {
          let respData = resp.data || {};
          let respResult = respData.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            _that.pageAjax.data = respResult.list || [];
            if (respResult.pagination) {
              _that.pageAjax.paging = {
                pages: respResult.pagination.pages,
                current: respResult.pagination.current,
                total: respResult.pagination.total,
                pageSize: respResult.pagination.pageSize
              };
            }
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {
          _that.pageAjax.loading = false;
        });
    },
    getDepData() {
      let _that = this;

      let data = {};
      _that.depSupAjax.loading = true;
      data.deptIds = _that.$route.query.id;
      getFinalCost({ params: data })
        .then(resp => {
          let respData = resp.data || {};

          if (respData.code === _that.STATUS.success[0]) {
            let reapResult = respData.data || [];
            _that.depSupAjax.data = reapResult[0] || {};
          } else {
            _that.$message.error(respData.msg || "获取失败");
          }
        })
        .finally(() => {
          _that.depSupAjax.loading = false;
        });
    },
    getOrgData() {
      let _that = this;
      _that.$store.dispatch("getDepartmentList").then(() => {
        let arr = _.cloneDeep(_that.$store.state.departmentList) || [];
        _that.orgSupAjax.data = getOffspringnTree(_.cloneDeep(arr), 0);
      });
    },
    navToDetail(id) {
      this.$router.push({
        name: "agent_detail",
        query: {
          anchorId: id
        }
      });
    },
    navToLiveDetail(id) {
      this.$router.push({
        name: "agent_liveDetail",
        query: {
          anchorId: id
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.page {
  .s-search {
    border-bottom: 1px solid #eee;
  }
  .c-aside {
    .btn {
      margin-right: 20px;
    }
    .diy-uploadBtn {
      margin-right: 20px;
    }
  }
  .c-main {
    margin-top: 20px;
    .c-avatar {
      display: block;
      width: 100px;
      height: 100px;
      border-radius: 50%;
    }
  }
  .c-pagination {
    margin-top: 20px;
    text-align: center;
  }
  .f-agentWish {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    bottom: 0;
    .c-content {
      height: 100%;
      padding-bottom: 20px;
      overflow: auto;
    }
    .c-card {
      .c-item {
        padding-bottom: 20px;
        border-top: 1px solid #f5f7fa;
      }
      .c-UserInfo {
        position: relative;
        overflow: hidden;
        line-height: 25px;
      }
      .c-avatar {
        float: left;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .c-nameInfo {
        float: left;
        margin-left: 20px;
      }
      .c-copyBtn {
        cursor: pointer;
        position: absolute;
        right: 0;
        top: 0;
        border: 1px solid #eee;
        padding: 10px 20px;
        border-radius: 20px;
      }
      .c-bid {
        overflow: hidden;
        line-height: 30px;
        img {
          float: left;
          width: 30px;
          height: 30px;
          margin-right: 20px;
        }
      }
    }
  }
  .f-agent {
    overflow: hidden;
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    bottom: 0;
    .c-content {
      height: 100%;
      padding-bottom: 20px;
      padding-top: 60px;
      overflow: auto;
    }
    .c-avatar {
      width: 80px;
      height: 80px;
    }
  }
}
</style>
<style lang="scss">
.page {
  .el-drawer__header {
    position: relative;
    z-index: 10;
  }
}
</style>
